<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>查询天气</title>
        <script src="jquery.min.js"></script>
    </head>
    <body>
        <div>
            <h2>杨凌区天气预报</h2>
            日期<input value="2022-11-16">
            <button >查询</button><br/>
            <textarea id="answer" cols="30" rows="10"></textarea>
        </div>
        <script>
            let url = "https://mock.apifox.cn/m1/1893392-0-default/cityweather?predictDate=";
            function  Weather(){
                let date = $("input").val()
                $.get({
                    url: url + date,
                    success: function (obj){
                        let str = "";
                        if(obj.code >= 0){
                            let ans = obj.data.forecast[0];
                            str += "白天天气:"+ans.conditionDay+'\n';
                            str += "晚间天气:"+ans.conditionNight+'\n';
                            str += "最高温:"+ans.tempDay+`&#8451`+'\n';
                            str += "最低温:"+ans.tempNight+`&#8451`+'\n';
                            document.getElementById("answer").innerHTML=str;
                        }
                        else{
                            document.getElementById("answer").innerHTML= "数据未找到";
                        }
                    }
                })
            }
            $("button").click(Weather)
        </script>
    </body>
</html>